home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- /*
- * routines to maintain a list of mailfiles for which warning messages have
- * been sent out, plus routines to send out warning and failure messages.
- *
- * Written by Jim Crammond <jim@cs.hw.ac.uk> 3/86
- */
-
- #define SENDMAIL "/usr/lib/sendmail"
- #define NAMESIZE 15
- #define BLKSIZE ((BUFSIZ/NAMESIZE) - 1)
-
- struct flist
- { char fname[BLKSIZE][NAMESIZE];
- int nused;
- struct flist *next;
- };
-
-
- struct flist warnlist;
- FILE *warnfp;
-
-
- /*
- * Initialise list of files for which warning messages have already been sent.
- * This involves reading the warnfile into a table, removing files which
- * no longer exist (i.e. been sent or deleted), and writing this out again.
- */
- init_warnedlist(warnfile)
- char *warnfile;
- {
- struct flist *wp;
- char warned[NAMESIZE], *p;
- int i;
- char *index();
-
- wp = &warnlist;
- wp->next = NULL;
- wp->nused = 0;
-
- if ((warnfp = fopen(warnfile, "r")) != NULL)
- { while (fgets(warned, NAMESIZE, warnfp) != NULL)
- { if ((p = index(warned, '\n')) != NULL)
- *p = '\0';
-
- if (exists(warned))
- { if (wp->nused >= BLKSIZE)
- { wp->next = (struct flist *) malloc(sizeof(warnlist));
- wp = wp->next;
- wp->next = (struct flist *) NULL;
- wp->nused = 0;
- }
- strcpy(wp->fname[wp->nused], warned);
- wp->nused++;
- }
- }
- fclose(warnfp);
- }
-
- /*
- * Rewrite warnedlist removing files that no longer exist.
- * Could be really paranoid here and create a temporary file
- * first, rather than overwrite; in case of crashed
- */
- if ((warnfp = fopen(warnfile, "w")) != NULL)
- { wp = &warnlist;
- while (wp)
- { for (i=0; i < wp->nused; i++)
- fprintf(warnfp, "%s\n", wp->fname[i]);
- wp = wp->next;
- }
- fflush(warnfp);
- }
- }
-
- /*
- * Determine whether the given filename is in the warn list.
- * Returns 1 if found, 0 otherwise.
- */
- in_warnedlist(file)
- char *file;
- {
- struct flist *wp = &warnlist;
- int i;
-
- while (wp)
- { for (i=0; i < wp->nused; i++)
- { if (strcmp(file, wp->fname[i]) == 0)
- return(1);
- }
- wp = wp->next;
- }
- return(0);
- }
-
- /*
- * Add a filename to the warn list.
- */
- add_warnedlist(file)
- char *file;
- {
- fprintf(warnfp, "%s\n", file);
- }
-
-
- /*
- * Send a Failed Mail message back to the sender, containing the whole
- * of the failed message.
- */
- sendfailure(sender, rcpts, host, hours, msgfile)
- char *sender;
- char **rcpts;
- char *host;
- int hours;
- char *msgfile;
- {
- FILE *out, *popen();
- char cmd[50];
-
- sprintf(cmd, "%s -t", SENDMAIL);
- out = popen(cmd, "w");
- fprintf(out, "From: MAILER-DAEMON\nSubject:Failed Mail\nTo: %s\n\n", sender);
- fprintf(out, "After %d days (%d hours), your message to the following people:\n\n", hours/24, hours);
-
- /* put out recipents */
- while (*rcpts)
- { fprintf(out, "\t%s (host=%s)\n", *rcpts, host);
- rcpts++;
- }
-
- fprintf(out, "\ncould not be delivered.\n\n");
- fprintf(out, " ----- Unsent message follows ----- \n");
-
- /* print all of the message */
- print_message(msgfile, out, 0);
- pclose(out);
-
- return;
- }
-
-
- /*
- * Send a Waiting Mail message back to the sender, containing a summary
- * of the delayed message (to remind him/her what it was about!).
- */
- sendwarning(sender, rcpts, host, hours, failtime, msgfile)
- char *sender;
- char **rcpts;
- char *host;
- int hours;
- int failtime;
- char *msgfile;
- {
- FILE *out, *popen();
- char cmd[50];
-
- sprintf(cmd, "%s -t", SENDMAIL);
- out = popen(cmd, "w");
- fprintf(out, "From: MAILER-DAEMON\nSubject:Waiting Mail\nTo: %s\n\n",
- sender);
- fprintf(out, "After %d days (%d hours), your message to the following people:\n\n", hours/24, hours);
-
- /* put out recipents */
- while (*rcpts)
- { fprintf(out, "\t%s (host=%s)\n", *rcpts, host);
- rcpts++;
- }
-
- fprintf(out, "\nhas not yet been delivered. Attempts to deliver the message will\n");
- fprintf(out, "continue for %d more days. No further action is required by you.\n\n", (failtime-hours)/24);
- fprintf(out, " ----- Queued message begins ----- \n");
-
- /* print a summary of the message */
- print_message(msgfile, out, 1);
- pclose(out);
-
- return;
- }
-